package com.aaa.controller;

import com.aaa.service.S_RegistService;
import com.aaa.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/regist/")
public class S_RegistController {
    @Autowired
    private S_RegistService service;

    /**
     * @return  注册时的通知公告
     */
    @RequestMapping("affiche")
    public String toAffiche(){
        return "register/affiche";
    }

    /**
     * @return  定向到注册界面
     */
    @RequestMapping("toRegist")
    public String toRegiste(){
        return "register/regist";
    }

    /**
     * @return  注册完成跳转界面
     */
    @RequestMapping("done")
    public String toDone(){
        return "register/done";
    }

    @RequestMapping("sellist")
    @ResponseBody
    public Object selList(){
        List<Map> org=service.selManage();//所属单位 下拉列表
        List<Map> type=service.selType();// 单位类别
        List<Map> nature=service.selNature();// 单位性质
        List<Map> industry=service.selIndustry();// 所属行业
        List<Map> grading=service.selGrading();// 申报等级
        Map zmap=new HashMap();
        zmap.put("org",org);
        zmap.put("types",type);
        zmap.put("natures",nature);
        zmap.put("industrys",industry);
        zmap.put("gradings",grading);
        return zmap;

    }

    /**  注册事件。写入单位信息
     * @param map
     * @return
     */
    @RequestMapping("add")
    @ResponseBody
    public Integer addUnit(@RequestBody Map map){
        System.out.println(map.get("password"));
        MD5 md5=new MD5();
        String password= (String) md5.MD5((String) map.get("password"));
        map.put("password2",password);
        System.out.println("1111"+map);
        int row = service.addUnit(map);

        service.addEmp(map);
        return row;
    }
}
